//<feature charts>
Ext.define('AkData.view.Pasta', {
    extend: 'Ext.Panel',
    requires: ['Ext.chart.PolarChart', 'Ext.chart.series.Pie', 'Ext.chart.interactions.Rotate'],
	
    config: {
		layout: 'fit',
		
        items: [
            {
                xtype: 'toolbar',
				docked: 'top',
				items: [
                    {
                        iconCls: 'refresh',
						style: {'background': '#E8E8E8', 'color': 'black'},
                        handler: function () {
							Ext.Viewport.mask({xtype: 'loadmask', message: _lang_Yukleniyor});
							Ext.getStore('KaliteBazindaUretim_Store').load(function(records, operation, success) {Ext.Viewport.unmask();}, this);
                        }
                    },
				]
            },
			{
                xtype: 'polar',
                store: 'KaliteBazindaUretim_Store',
                colors: AkData.view.ColorPatterns.getBaseColors(),
                interactions: ['rotate', 'itemhighlight'],
				id: 'Pasta_Chart',
				hidden: false,
				animate: true,
                legend: {
                    docked: 'right',
                    verticalWidth: 100,
					hidden: false,
                },
                innerPadding: 45,
                series: [
                    {
						title: 'Title',
                        type: 'pie',
						listeners: {
							afterrender: function() {
								console.log('afterrender');
							}
						},
                        label: {
							field: ['periyod'],
							display: 'none',
							//contrast: true,
							//orientation: 'horizontal',
							renderer: function (val, label, storeItem, item, i, display, animate, index) {
								console.log(val);
								/*
								var store = chart.getStore();
								var index = store.find('month', value);
								var record = store.getAt(index);
								return record.get('month') + ' : $' + record.get('salary');
								*/
								return val + '%';
							}
						},
						xField: 'gabardin',
                        donut: 30,
                        highlightCfg: {margin: 20},
						
						/*
						renderer: function (sprite, config, rendererData, index) {
							console.log(rendererData);
							if (index % 2 == 0) {
								return { strokeStyle: 'red' };
							}
						},
						*/
						style: {
                            stroke: 'white',
                            miterLimit: 10,
                            lineCap: 'miter',
                            lineWidth: 2
                        },
						
						renderer: function(sprite, config, rendererData, index) {
                            var store = rendererData.store,
                                storeItems = store.getData().items,
                                last = storeItems.length - 1,
                                record = storeItems[index],
                                diff = record && Math.round(record.data['gabardin'] - 100),
                                surface = sprite.getParent(),
                                textSprites, textSprite, rectSprite;
                            if (!record) {
                                return;
                            }
                            // This renderer function draws a red label if series #2 is greater than series #1.
                            // The label displays the difference between the values of series #1 and series #2.
                            //
                            // Note: The two renderer functions in this test case cannot be consolidated. The red labels
                            // are rendered here because they are positioned relatively to the series #2 columns.
                            if (diff > 0) {
                                textSprites = surface.myTextSprites;
                                if (!textSprites) {
                                    textSprites = surface.myTextSprites = [];
                                }
                                textSprite = textSprites[index];
                                if (!textSprite) {
                                    textSprite = textSprites[index] = surface.add({type:'text'});
                                    rectSprite = textSprite.rectSprite = surface.add({type:'rect'});
                                } else {
                                    rectSprite = textSprite.rectSprite;
                                    textSprite.show();
                                    rectSprite.show();
                                }

                                rectSprite.setAttributes({
                                    x: config.x + (index == last ? -18 : 20),
                                    y: config.y - 36,
                                    width: 36 + (diff >= 10 ? (diff >= 100 ? (diff >= 1000 ? 30 : 20) : 10) : 0),
                                    height: 22,
                                    fill: 'tomato',
                                    stroke: 'black',
                                    radius: 4,
                                    opacity: 1,
                                    zIndex: 10000
                                });

                                textSprite.setAttributes({
                                    text: "+ " + diff,
                                    x: config.x + (index == last ? -12 : 28),
                                    y: config.y - 20,
                                    fill: 'black',
                                    fontSize: 16,
                                    zIndex: 10001,
                                    //scalingY: -1
                                });
                            } else {
                                textSprites = surface.myTextSprites;
                                if (textSprites) {
                                    textSprite = textSprites[index];
                                    if (textSprite) {
                                        textSprite.rectSprite.hide();
                                        textSprite.hide();
                                    }
                                }
                            }
                            return null;
                        }
						
						/*
                        style: {
                            stroke: 'white',
                            miterLimit: 10,
                            lineCap: 'miter',
                            lineWidth: 2
                        }
						*/
                    },	
                ],
                axes: []
            }
        ]
    },
	
    initialize: function () {
		this.callParent();
		
		var task = Ext.create('Ext.util.DelayedTask', function() {
			Ext.Viewport.mask({xtype: 'loadmask', message: _lang_Yukleniyor});
			Ext.getStore('KaliteBazindaUretim_Store').load(function(records, operation, success) {
				Ext.Viewport.unmask();
				//Ext.getCmp('ornekler').show();
				Ext.getCmp('Pasta_Chart').setHidden(false);
				Ext.getCmp('Pasta_Chart').getLegend().setHidden(false);
			}, this);
		}, this);

		task.delay(500);
    }
	
});
//</feature>
